﻿import re, os

def FormatStr(str):
    #去除特殊符号 和换行 只保留汉字，字母、数字
    return re.sub(u"([^\u4e00-\u9fa5\u0030-\u0039\u0041-\u005a\u0061-\u007a])","",str)

def NumFormatStr(str):
    str1 = re.sub("([^u0041-\u005a\u0061-\u007a])","",str.strip())
    return Nospciel(str1, "nbsp;").strip()

def Nospciel(str, spci):
    return str.replace(spci, '')

def startwith(strsrc, start):
    if isinstance(strsrc,str):
        return strsrc.startswith(start)
    else:
        return None

def AddrConver(str):
    return str.replace('/','//')
    
#D:\Document\py\workspace\robotFrame\workspace\vhl\VHLTngDog\TestNG_Demo\FunLibTestNG    
def reversePath(abspath, iter):
    if isinstance(iter ,str):
        iter = int(iter)
    if iter is None or iter == 0:
        return abspath
    else:
        path = abspath
        # 路径的深度
        times = path.count('\\') or path.count('/')
        if iter >= times:
            # 翻转到路径最大深度，返回盘符
            return path[0:path.find('\\') or path.find('/') ]
        else:
            for i in range(0, iter):
                path = os.path.dirname(path)
            return path


if __name__ == '__main__':
    print(reversePath("D:\Document\py\workspace\robotFrame\workspace\vhl\VHLTngDog\TestNG_Demo\FunLibTestNG"))
